package com.guigu.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guigu.base.entity.TransportTrips;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.base.mapper.TransportTripsMapper;
import com.guigu.base.service.TransportTripsService;
import com.guigu.common.utils.Constant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 车次信息表 服务实现类
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-08
 */
@Service
public class TransportTripsServiceImpl extends ServiceImpl<TransportTripsMapper, TransportTrips> implements TransportTripsService {

    /**
     * 添加车次
     *
     * @param pdTransportTrips 车次信息
     * @return 车次信息
     */
    @Override
    public TransportTrips saveTransportTrips(TransportTrips pdTransportTrips) {
        baseMapper.insert(pdTransportTrips);
        return pdTransportTrips;
    }

    /**
     * 获取车次列表
     *
     * @param transportLineId 线路id
     * @param ids             车次id列表
     * @return 车次列表
     */
    @Override
    public List<TransportTrips> findAll(String transportLineId, List<String> ids) {
        LambdaQueryWrapper<TransportTrips> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(transportLineId)) {
            lambdaQueryWrapper.eq(TransportTrips::getTransportLineId, transportLineId);
        }
        if (ids != null && ids.size() > 0) {
            lambdaQueryWrapper.in(TransportTrips::getId, ids);
        }
        lambdaQueryWrapper.orderBy(true, true, TransportTrips::getId);
        lambdaQueryWrapper.eq(TransportTrips::getStatus, Constant.DATA_DEFAULT_STATUS);
        return baseMapper.selectList(lambdaQueryWrapper);
    }

    /**
     * 删除车次
     *
     * @param id
     */
    @Override
    public void disable(String id) {
        TransportTrips pdTransportTrips = new TransportTrips();
        pdTransportTrips.setId(id);
        pdTransportTrips.setStatus(Constant.DATA_DISABLE_STATUS);
        baseMapper.updateById(pdTransportTrips);
    }
}
